package GUIadapter;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import ModelLayer.SaleItem;

@SuppressWarnings("serial")
public class TableSaleItemAdapterModel extends AbstractTableModel
{
	private final String[] columnHeader= {"Index",
                                        "Item Description",
                                        "Price",
                                        "Amount in stock",
                                        "Location",
                                        "Barcode"};
	
	private List<SaleItem> saleItemList;

	public TableSaleItemAdapterModel(List<SaleItem> saleItemList)
	{
		// TODO Auto-generated constructor stub
		this.saleItemList = saleItemList;
	}

	@Override
	public String getColumnName(int column)
	{
		// TODO Auto-generated method stub
		return columnHeader[column];
	}

	@Override
	public int getColumnCount()
	{
		// TODO Auto-generated method stub
		return columnHeader.length;
	}

	@Override
	public int getRowCount()
	{
		// TODO Auto-generated method stub
		return saleItemList.size();
	}

	@Override
	public Object getValueAt(int row, int col)
	{
		// TODO Auto-generated method stub
		SaleItem saleItem = saleItemList.get(row);
		switch(col)
		{
		case 0:
			return new Integer(row);//index
		case 1:
			return saleItem.getDescription();
		case 2:
			return new Double(saleItem.getPrice());
		case 3:
			return new Integer(saleItem.getInStock());
		case 4:
			return saleItem.getLocation();
		case 5:
			return saleItem.getBarCode();
		}

		return null;//should never reach here..!
	}

} // end TableSaleItemAdapterModel
